<!--
 * @Author: zhangmengqiong
 * @Date: 2021-05-10 17:43:06
 * @LastEditors: zhangmengqiong
 * @LastEditTime: 2021-05-11 16:59:38
-->
<template>
  <div class="sales-view">
    <el-card shadow="hover" :body-style="{ padding: '0 0 20px 0' }">
      <template v-slot:header>
        <div class="menu-wrapper">
          <el-menu
            mode="horizontal"
            :default-active="activeIndex"
            @select="menuSelect"
            class="sales-menu"
          >
            <el-menu-item index="1">销售额</el-menu-item>
            <el-menu-item index="2">访问量</el-menu-item>
          </el-menu>
          <div class="menu-right">
            <el-radio-group v-model="radioSelect" size="small">
              <el-radio-button label="今日"></el-radio-button>
              <el-radio-button label="本周"></el-radio-button>
              <el-radio-button label="本月"></el-radio-button>
              <el-radio-button label="今年"></el-radio-button>
            </el-radio-group>
            <el-date-picker
              class="date"
              v-model="date"
              size="small"
              type="daterange"
              unlink-panels
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :picker-options="pickerOptions"
            >
            </el-date-picker>
          </div>
        </div>
      </template>
      <template>
        <div class="slaes-view-chart-wrapper">
          <v-chart :option="chartOption" />
          <div class="slaes-view-list">
            <div class="slaes-view-list-title">排行榜</div>
            <div class="list-wrapper ">
              <div class="list" v-for="item in rankData" :key="item.id">
                <div class="list-num" :class="{ 'top-num': item.num < 4 }">
                  {{ item.num }}
                </div>
                <div class="list-name">{{ item.name }}</div>
                <div class="list-money">{{ item.moeney }}</div>
              </div>
            </div>
          </div>
        </div>
      </template>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "SaleView",
  props: {
    msg: String
  },
  data() {
    return {
      activeIndex: "1",
      radioSelect: "今日",
      date: "",
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      },
      chartOption: {
        title: {
          text: "年度销售额",
          textStyle: {
            fontSize: 12,
            color: "#666"
          },
          left: 25,
          top: 20
        },
        tooltip: {
          trigger: "axis"
        },
        xAxis: {
          type: "category",
          data: [
            "Mon",
            "Tue",
            "Wed",
            "Thu",
            "Fri",
            "Sat",
            "Sun",
            "Fri",
            "Sat",
            "Sun"
          ],
          axisTick: {
            alignWithLabel: true, // 短竖线在中间
            lineStyle: {
              color: "#999"
            }
          },
          axisLine: {
            lineStyle: {
              color: "#999"
            }
          },
          axisLabel: {
            color: "#333"
          }
        },
        yAxis: {
          type: "value",
          splitLine: {
            lineStyle: {
              type: "dotted",
              color: "#eee"
            }
          }
        },
        series: [
          {
            data: [150, 230, 224, 218, 135, 147, 260, 224, 218, 135],
            barWidth: "35%",
            type: "bar"
          }
        ],
        grid: {
          top: 70,
          left: 60,
          right: 60,
          bottom: 50
        }
      },
      rankData: [
        { id: 1, num: 1, name: "麦当劳1", moeney: 34 },
        { id: 2, num: 2, name: "麦当劳2", moeney: 35 },
        { id: 3, num: 3, name: "麦当劳3", moeney: 39 },
        { id: 4, num: 4, name: "麦当劳4", moeney: 40 },
        { id: 5, num: 5, name: "麦当劳6", moeney: 41 },
        { id: 6, num: 6, name: "麦当劳5", moeney: 43 },
        { id: 7, num: 7, name: "麦当劳7", moeney: 44 }
      ]
    };
  },
  methods: {
    menuSelect(index) {
      this.activeIndex = index;
    }
  }
};
</script>

<style scoped lang="scss">
.sales-view {
  margin-top: 20px;
  .menu-wrapper {
    position: relative;
    display: flex;
    .sales-menu {
      width: 100%;
      padding-left: 20px;
      box-sizing: border-box;
      .el-menu-item {
        height: 50px;
        line-height: 50px;
        margin: 0 20px;
      }
    }
    .menu-right {
      position: absolute;
      right: 20px;
      top: 0;
      height: 50px;
      line-height: 50px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .date {
        margin-left: 20px;
      }
    }
  }
  .slaes-view-chart-wrapper {
    display: flex;
    height: 270px;
    .echarts {
      flex: 0 0 72%;
      width: 72%;
      height: 100%;
    }
    .slaes-view-list {
      .slaes-view-list-title {
        font-size: 12px;
        margin-top: 20px;
        color: #666;
        font-weight: 500;
      }
      flex: 1;
      width: 100%;
      height: 100%;
      overflow: hidden;
      .list-wrapper {
        margin-top: 15px;
        .list {
          display: flex;
          font-size: 12px;
          height: 20px;
          line-height: 20px;
          align-items: center;
          padding: 6px 20px 6px 0;
          .list-num {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 20px;
            height: 20px;
            &.top-num {
              border-radius: 50%;
              font-weight: 500;
              color: #fff;
              background: #333;
            }
          }
          .list-name {
            margin-left: 10px;
            color: #333;
          }
          .list-money {
            flex: 1;
            text-align: right;
          }
        }
      }
    }
  }
}
</style>
